﻿/* mvcForum
 * Copyright (C) 2010-2011 Steen F. Tøttrup
 * http://mvcforum.org/
 */

using System;
using System.ComponentModel.DataAnnotations;

namespace mvcForum.Core {

	/// <summary>
	/// This class represents an access mask for a given board.
	/// </summary>
	public class AccessMask {
		public AccessMask() { }
		public AccessMask(Board board, string name, AccessFlag flag) {
			this.Board = board;
			this.Name = name;
			this.AccessFlag = flag;
		}

		#region Properties
		/// <summary>
		/// The Id of the access mask.
		/// </summary>
		public Int32 Id { get; set; }
		/// <summary>
		/// The board the access mask belongs to.
		/// </summary>
		[Required]
		public Int32 BoardId { get; set; }
		public virtual Board Board { get; set; }
		/// <summary>
		/// Name of the access mask.
		/// </summary>
		[StringLength(Constants.FieldLengths.AccessMaskName)]
		[Required]
		public String Name { get; set; }
		/// <summary>
		/// The access this access mask grants right to.
		/// </summary>
		public AccessFlag AccessFlag {
			get {
				return (AccessFlag)this.AccessFlagValue;
			}
			set {
				this.AccessFlagValue = (Int32)value;
			}
		}
		/// <summary>
		/// 		 Int32 representation of the AccessFlag.
		///		 (Entity Framework 4.1 does not support enums, this is a "fix")
		/// </summary>
		[Required]
		public Int32 AccessFlagValue { get; set; }
		#endregion
	}
}